// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// File:	projectscheduler.h
// Author: 	Kirk Larkin
// Date: 	25/09/2008
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#ifndef __PROJECTSCHEDULER_H__
#define __PROJECTSCHEDULER_H__

// Qt Includes
#include <QObject>
#include <QString>
#include <QDateTime>
#include <QList>
#include <QQueue>

// Local Declarations
class ScheduledProject;

// Local Includes
#include "../project.h"

// ******************************************************************
// ProjectScheduler
// ******************************************************************
class ProjectScheduler : public QObject
{
	Q_OBJECT

// TODO: Add states to the scheduler (eg, running, paused, stopped, etc).

public:
// Construction & Destruction
	ProjectScheduler(const QString &strConfigFilePath = QString(), // If specified, the projects will be loaded from here.
			QObject *pParent = NULL);

// Member Functions
	bool addProject(const QString &strProjectPath,
			const QTime &tmProjectSchedule);

protected:
// Overrides
	void timerEvent(QTimerEvent *pEvent);

private slots:
	void onCurrentProjectComplete(Project::tProjectState eProjectState);

private:
// Member Functions
	bool loadConfigFile(const QString &strConfigFilePath);
	bool startNextProject();
	
	void logMessage(const QString &strLogMessage) const;

// Member Variables
	ScheduledProject *m_pCurrentProject; // The project currently being run.
	QList<ScheduledProject*> m_lstProjects; // A collection of all configured projects.
	QQueue<ScheduledProject*> m_quProjects; // The active queue of projects, all ready to be run ASAP.
	QString m_strLogPath; // The log path for the scheduler.
};

#endif // #ifndef __PROJECTSCHEDULER_H__
